package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/16 13:21
 **/
public class Day31_3_Num55_CanJump {
    class Solution {
        public boolean canJump(int[] nums) {
            int mostLong = 0;
            for(int i = 0;i <= nums.length-1;i++){
                if(i <= mostLong){
                    mostLong = Math.max(mostLong, i + nums[i]);
                    if(mostLong >= nums.length - 1) return true;
                }
            }
            return false;
        }
    }

    class Solution2 {
        public boolean canJump(int[] nums) {
            int mostLong = 0;
            for(int i = 0;i < nums.length-1;i++){
                mostLong = Math.max(mostLong, i + nums[i]);
                if(nums[i] == 0 && mostLong <= i) return false;
            }
            return true;
        }
    }
}